<?php
$host = '127.0.0.1';
$dbuser = 'root';
$pwd = 'root';
$dbname = 'phptest';
$db = new mysqli($host,$dbuser,$pwd);

$db->query("CREATE DATABASE IF NOT EXISTS $dbname");

$db->query("USE $dbname");

//指定数据库编码为UTF8
$db->query('SET NAMES UTF8');

$db->query("CREATE TABLE IF NOT EXISTS msg(
	id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
	content VARCHAR(255) NOT NULL,
	user VARCHAR(100) NOT NULL,
	time INT(10) NOT NULL
)ENGINE=InnoDB DEFAULT CHARSET=utf8;");

$db->query("CREATE TABLE IF NOT EXISTS account(
	id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
	username VARCHAR(100) NOT NULL,
	password VARCHAR(16) NOT NULL
)ENGINE=InnoDB DEFAULT CHARSET=utf8;");



if(!$db){
	die('数据库连接失败');
}
?>